//
//  String+Date.swift
//  CMCCIOTSwift
//
//  Created by isoftstone on 2017/4/18.
//  Copyright © 2017年 isoftstone. All rights reserved.
//

import Foundation
//MARK:- String->Date
extension String{
    
    func formatDate(format : String?) -> Date {
        let formatter = DateFormatter()
        formatter.dateFormat = format
        return formatter.date(from: self)!
    }
}
//MARK: - Date->String
extension Date{
    
    func formatString(format : String?) -> String {
        let formatter = DateFormatter()
        formatter.dateFormat = format
        return formatter.string(from: self)
    }
}
//MARK:- 计算星期几 从0->周日 开始
extension Date{
    func week() -> Int{
        let interval = self.timeIntervalSince1970
        let day = Int(interval/86400)
        return (day - 3) % 7
    }
    func weekFull() -> String {
        
        let weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
        return weeks[self.week()]
    }
    func weekBrief() -> String {
        let weeks = ["日","一","二","三","四","五","六"]
        return weeks[self.week()]
    }
}
